package com.witmed.lib_http

import android.os.Environment
import com.zyj.retrofit.adapter.FlowCallAdapterFactory
import okhttp3.Cache
import okhttp3.CacheControl
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import java.io.File
import java.util.concurrent.TimeUnit


abstract class BaseRetrpfitImpl:HttpRetrofit {
    override fun createRetrofit(client: OkHttpClient?): Retrofit? {

        var retrofit=Retrofit.Builder()
            .baseUrl(Concast.BASE_URL)
            .client(client)
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .build()
        return retrofit
    }

    open fun createOkHttpBuilder():OkHttpClient.Builder?{

        val builder=OkHttpClient.Builder()
        builder
            .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .readTimeout(readTimeout(),TimeUnit.SECONDS)
            .connectTimeout(connectTimeout(),TimeUnit.SECONDS)
            .writeTimeout(writeTimeout(),TimeUnit.SECONDS)
        return builder
    }

    abstract fun readTimeout():Long
    abstract fun connectTimeout():Long
    abstract fun writeTimeout():Long

}